<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
  /**
   * Run the migrations.
   *
   * @return void
   */
  public function up()
  {
    Schema::create('cities', function (Blueprint $table) {
      $table->id();
      $table->bigInteger('district_id')->unsigned();
      $table->string('name');
      $table->date('from')->nullable();
      $table->date('to')->nullable();
      $table->boolean('active')->default(true);
      $table->timestamps();
      // Foreign keys constraints
      $table->foreign('district_id')->references('id')->on('districts')->onDelete('restrict');
      // Unique candidate key constraints
      $table->unique(['district_id', 'name']);
    });
  }

  /**
   * Reverse the migrations.
   *
   * @return void
   */
  public function down()
  {
    Schema::dropIfExists('cities');
  }
};
